//
//  UIBarButtonItme + Extension.swift
//  SinWEiBo
//
//  Created by 胡良志 on 2018/3/11.
//  Copyright © 2018年 HuLiangZhi. All rights reserved.
//

import UIKit

//MARK: 给UIBarButtonItme扩展构造方法
extension UIBarButtonItem{
    
    /// 扩展的构造方法UIBarButtonItme
    ///
    /// - Parameters:
    ///   - title: 要显示的文字
    ///   - imageName: 要显示的图片
    ///   - target: target
    ///   - action: 执行方法
    convenience init(title:String = "",imageName:String = "",target:Any?,action:Selector?) {

        let button = UIButton()
        button.setTitle(title, for: .normal)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setTitleColor(UIColor.orange, for: .highlighted)
        button.setImage(UIImage(named: imageName), for: .normal)
        button.setImage(UIImage(named:imageName + "_highlighted"), for:.highlighted)
        
        if let ac = action{
            button.addTarget(target, action: ac, for: .touchUpInside)
        }
        button .sizeToFit()
        self.init()
        self.customView = button
    }
}
















